package test;


import com.thoughtworks.xstream.XStream;
import entity.*;
import net.sf.json.JSONObject;
import org.junit.Test;
import service.Service;
import util.Util;

import javax.xml.stream.XMLStreamConstants;
import java.util.HashMap;
import java.util.Map;

public class teste{
    @Test
    public void testMsg(){
        Map<String,String>map=new HashMap<>();
        map.put("ToUserName","to");
        map.put("FromUserName","from");
        map.put("MsgType","type");
        TextMessage tm=new TextMessage(map,"还好");
        XStream stream=new XStream();
        stream.processAnnotations(TextMessage.class);
        String xml=stream.toXML(tm);
        System.out.println(xml);

    }
    @Test
    public void testToken(){
        System.out.println(Service.getAccessToken());
        System.out.println(Service.getAccessToken());
    }

    @Test
    //菜单测试
    public void testButton(){
        Button btn=new Button();
        btn.getButton().add(new ClickButton("一级点击","1"));
        btn.getButton().add(new ViewButton("一级跳转","http://vaudqi.natappfree.cc"));
        SubButton sb=new SubButton("有子菜单");
        sb.getSub_button().add(new PhotoOrAlbumButton("传图","31"));
        sb.getSub_button().add(new ClickButton("点击","32"));
        sb.getSub_button().add(new ViewButton("网易","http://vaudqi.natappfree.cc "));
        btn.getButton().add(sb);
        JSONObject jsonObject=JSONObject.fromObject(btn);
        //准备url
        String url=" https://api.weixin.qq.com/cgi-bin/menu/create?access_token=ACCESS_TOKEN";
        url=url.replace("ACCESS_TOKEN",Service.getAccessToken());
        //发送请求
        String result= Util.post(url,jsonObject.toString());
        System.out.println(result);
    }
    @Test
    //行业设置
    public  void set(){
        String url="https://api.weixin.qq.com/cgi-bin/template/api_set_industry?access_token=ACCESS_TOKEN";
        url=url.replace("ACCESS_TOKEN",Service.getAccessToken());
        String data="{ \"industry_id1\":\"1\", \"industry_id2\":\"4\"}";
        String result=Util.post(url,data);
        System.out.println(result);
    }
    @Test
    //行业查询
    public void get(){
        String url="https://api.weixin.qq.com/cgi-bin/template/get_industry?access_token=ACCESS_TOKEN";
        url=url.replace("ACCESS_TOKEN",Service.getAccessToken());
        String result=Util.get(url);
        System.out.println(result);
    }
    //发送模板
    @Test
    public void send(){
        String url="https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=ACCESS_TOKEN";
        url=url.replace("ACCESS_TOKEN",Service.getAccessToken());
        String data="";
        String result=Util.post(url,data);
        System.out.println(result);

    }

}
